// import simulateBookSprite from "./simulateBookSprite";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    bezierPage: cc.Node = null;
    @property(cc.Node)
    verletPage: cc.Node = null;

    bounceSpeed: number = 500;

    onLoad() {
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.touchMove, this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchMove, this);
        // let sp = this.verletPage.getComponent(cc.Sprite);
        // cc.tween(sp)
        //     .repeatForever(
        //         cc.tween()
        //             .to(2, { bookAngle: 180 })
        //             .delay(2)
        //             .to(2, { bookAngle: 0 })
        //             .delay(2)
        //     )
        //     .start()
        let sp1 = this.bezierPage.getComponent(cc.Sprite);
        cc.tween(sp1)
            .repeatForever(
                cc.tween()
                    .to(2, { bookAngle: 180 })
                    .delay(2)
                    .to(2, { bookAngle: 0 })
                    .delay(2)
            )
            .start()
    }
    touchMove(touch) {
        let sp = this.verletPage.getComponent(cc.Sprite);
        if (sp) {
            let percent = touch.getDelta().x * 0.5;
            // let percent = ((touch.getLocation().x - cc.winSize.width / 2) / cc.winSize.width) * 2;
            // console.log('percent', percent)
            if (sp['bookAngle'] - percent >= 0 && sp['bookAngle'] - percent <= 180) {
                sp['bookAngle'] -= percent;
            }
        }
    }

    update(dt) {

    }
}
